<template>
    <div class="order-view">
        <el-drawer title="客户修改" :before-close="handleClose" :visible.sync="addVisible" direction="rtl"
            custom-class="demo-drawer" ref="drawer">
            <div class="demo-drawer__content">
                <el-form>
                    <el-form-item label="姓名: " prop="cusName" :label-width="formLabelWidth">
                        <el-input v-model="cusName" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="联系方式: " prop="cusPhone" :label-width="formLabelWidth">
                        <el-input v-model="cusPhone" autocomplete="off"></el-input>
                    </el-form-item>
                </el-form>
                <div class="demo-drawer__footer" align="center">
                    <el-button @click="addVisible = false">取 消</el-button>
                    <el-button type="primary" @click="updCus()">修改</el-button>
                </div>
            </div>
        </el-drawer>
    </div>
</template>
<script>
export default {
    name: "UpdCustomer",
    data() {
        return {
            addVisible: false,
            cusName: '',
            cusPhone: '',
            formLabelWidth: '80px'
        };
    },
    mounted() {
    },
    methods: {
        handleClose() {
            this.addVisible = false;
        },

        addCustomer() {
            var phoneReg = /(^1\d{10}$)|(^[0-9]\d{7}$)/;
            if (this.cusName === '') {
                alert("姓名不能为空!");
                return;
            }
            if (this.cusPhone === '') {
                alert("联系方式不能为空!");
                return;
            }
            if (!phoneReg.test(this.cusPhone)) {
                alert("手机号码格式错误!");
                return;
            }
            this.$http.post("http://localhost:8087/finerCustomer/addCus", {
                userId: 1,
                cusName: this.cusName,
                cusPhone: this.cusPhone
            })
                .then((res) => {
                    if (res.data.code === '200') {
                        alert(res.data.message);
                        this.handleClose();
                    }
                })
        },

        //新增客户按钮
        addProductButton() {
            this.addVisible = true;
        },
    },
};
</script>

<style lang="scss"></style>